<template>
  <view class="order-form-container">
	  
		<uni-section title="订单名称" type="line" padding>
			<uni-easyinput class="uni-mt-5" trim="all" v-model="form.orderName" disabled placeholder="请输入任务名称" >
			</uni-easyinput>
		</uni-section>
	
		<uni-section title="环节名称" type="line" padding>
			<uni-easyinput class="uni-mt-5" trim="all" v-model="form.linkName"  disabled >
			</uni-easyinput>
		</uni-section>
		
		<uni-section title="申请人" type="line" padding>
			<uni-easyinput class="uni-mt-5" trim="all" v-model="form.createBy"  disabled >
			</uni-easyinput>
		</uni-section>
		
		<uni-section title="申请时间" type="line" padding>
			<uni-datetime-picker type="date" :clear-icon="false" v-model="form.createTime"  disabled/>
		</uni-section>
<!-- 	 
		<uni-section title="剩余数量" type="line" padding>
			<uni-easyinput class="uni-mt-5" trim="all" v-model="form.residueNumber"  disabled >
			</uni-easyinput>
		</uni-section> -->
		
		<uni-section title="已完成数量" type="line" padding>
			<uni-easyinput class="uni-mt-5" trim="all" v-model="form.inputNumber"  disabled >
			</uni-easyinput>
		</uni-section>
		
		<uni-section title="备注" type="line" padding>
			<uni-easyinput type="textarea" :disabled="isMyTask==1" class="item-textarea" placeholder="请输入" v-model="form.remark"></uni-easyinput>
		</uni-section>

		<uni-section style="padding-bottom: 20rpx;">
			<view class="submit-btn-container">
				<button v-if="orderStatus==1 && isMyTask==1" type="primary" size="mini" @click="submitForm(0)">撤回</button>
				<button v-if="orderStatus==1 && isMyTask!=1" type="primary" size="mini" @click="submitForm(2)">驳回</button>
				<button v-if="orderStatus==1 && isMyTask!=1" type="primary" size="mini" @click="submitForm(3)">通过</button>
			</view>
		</uni-section>

  </view>
</template>

<script>
import request from '/utils/request.js';
import { isEmpty } from "/utils/utils.js"

export default {
  data() {
    return {
      form: {
      	id: '',
      	linkName: '',
      	linkId: '',
      	orderName: '',
      	orderId: '',
      	residueNumber: '',
      	createBy: '',
      	createTime: '',
      	inputNumber: '',
      	paintFlag:'',
      	wireFlag:'',
      	status:'1', //1待审核 2不合格 3合格
				remark: '',
      },
			orderStatus: '',
			isSubmit: false,
			isMyTask: 1,
    }
  },
  onLoad(options) {
		this.form.linkName = options.linkName
		this.form.linkId = options.linkId
		this.form.orderName = options.orderName
		this.form.orderId = options.orderId
		// this.form.residueNumber = options.residueNumber
		this.form.inputNumber = options.inputNumber
		this.form.createBy = options.createBy
		this.form.createTime = options.createTime
		this.form.id = options.id
		this.orderStatus = options.orderStatus
		this.isMyTask = options.isMyTask
	},
  methods: {

    // 提交表单
    submitForm(type) {
			if (this.isSubmit) {
				return
			}
			this.form.status = type
			
			//校验必填项
			// if (isEmpty(this.form.orderName)) {
			// 	uni.showToast({
			// 		title: `请输入任务名称`,
			// 		icon: 'error',
			// 	})
			// 	return
			// }

      uni.showLoading({
        title: '提交中...',
      })

      let params = {
        ...this.form
      }
      request.put('/system/operation', params).then(res => {
        uni.hideLoading()
        if (res.code === 200) {
          uni.showToast({
            title: '操作成功',
            icon: 'success',
            duration: 1500, // 显示2秒
          });
          this.isSubmit = true
          // 等待提示框显示完成后再跳转
          setTimeout(() => {
            uni.switchTab({
              url: `/pages/tabBar/index/index`
            });
          }, 1500);
					// 跳转到任务列表页
					
					// uni.redirectTo({
					// 	url: '/pages/workorder/myApply'
					// })
					
        } else {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    },

	},
}
</script>

<style scoped lang="scss">
.order-form-container {
  padding: 20rpx;
}
.uni-form-item {
  margin-bottom: 20rpx;
  display: flex;
  flex-direction: column;
}
.uni-label {
  font-size: 28rpx;
  margin-bottom: 10rpx;
}
.uni-input {
  padding: 15rpx;
  border: 1px solid #ccc;
  border-radius: 6rpx;
  font-size: 28rpx;
  min-height: 50rpx;
}
.attachment-list {
  margin-top: 10rpx;
}
.attachment-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10rpx 0;
  border-bottom: 1px solid #eee;
}
.close-icon {
  color: #999;
  font-size: 24rpx;
  padding: 5rpx;
  cursor: pointer;
}
.uni-button {
  margin-top: 20rpx;
}


/* 表单容器样式调整 */
.order-form-container {
  padding: 20rpx;
  padding-bottom: 220rpx; /* 增加底部内边距，避免内容被按钮遮挡 */
  
  /* 动态计算底部内边距（替代固定值，更灵活） */
  padding-bottom: calc(120rpx + constant(safe-area-inset-bottom));
  padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
}

/* 兼容非全面屏设备的备用方案 */
:root {
  --bottom-space: 160rpx;
}
.order-form-container {
  padding-bottom: var(--bottom-space);
}

/* 针对不同设备的动态调整（JS控制） */
@media screen and (min-device-height: 812px) and (-webkit-device-pixel-ratio: 3) {
  :root {
    --bottom-space: 180rpx; /* iPhone X系列等全面屏设备 */
  }
}
@media screen and (min-device-height: 896px) and (-webkit-device-pixel-ratio: 3) {
  :root {
    --bottom-space: 200rpx; /* iPhone 12/13系列等全面屏设备 */
  }
}

.submit-btn-container {
	display: flex;
	padding-bottom: 40rpx;
}
</style>
